<?php
namespace app\admin\controller\goods;
use app\admin\controller\Controller;
use app\admin\service\Goods as GoodsModel;
use think\Db;
class Goods extends Controller
{
    /**
     * 商品列表(出售中)
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        // 获取全部商品列表
        $model = new GoodsModel;
        $list = $model->getList(array_merge(['status' => -1], $this->request->param()));
        return $this->fetch('index', compact('list'));
    }



    public function offdown(){
        $params=input();
        $goodsId=$params['goods_id'];
        $model = new GoodsModel;
        $goodsInfo=$model->where('goods_id',$goodsId)->find();
        if ($goodsInfo['goods_status']==20) {
            $this->error('该商品已审核下架，不能重复审核');
        }

        Db::transaction(function () use ($model ,$goodsInfo,$params) {
            $res=$model->where('goods_id',$params['goods_id'])->setField('goods_status',20);
            if($res){
                $ext= json_encode([
                    'goods_id'=>$params['goods_id'],
                ]);
                \app\common\model\store\StoreNotice::add($goodsInfo['wxapp_id'],1, $params['goods_id'],$params['message_title'],$params['message_content'],$ext);
            }
        });

        return $this->renderSuccess('操作成功');
    }


    public function detail($goods_id){
        // 订单详情
        $detail =GoodsModel::detail($goods_id);
        return $this->fetch('detail', compact('detail'));
    }


}